package com.redis.demo;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import com.redis.demo.api.PublishMsg;
import com.redis.demo.utils.MessageType;

/**
 * Hello world!
 *
 */
public class App2 
{
    public static void main( String[] args )
    {
    	PublishMsg publishMsg = new Publish();
    	//测试普通信息发送
    	Message message = new Message();
    	message.setType(MessageType.text);
    	message.setTopic("text");
    	message.setMessage("text message");
    	publishMsg.send(message);
    	//subscribeMsg.subscribe("object");
    	//subscribeMsg.subscribe("queue");
    	try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	//测试对象信息发送
    	Message m = new Message();
    	m.setType(MessageType.object);
    	m.setTopic("text");
    	User user = new User("test Object","13592294504");
    	m.setMessage(user);
    	publishMsg.send(m);
    	
    	
    	try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	//队列消息
    	final BlockingQueue linkQueue = new LinkedBlockingQueue();
    	Thread t = new Thread(new Runnable() {
			public void run() {
				for(int i=0;i<=5;i++){
					User u = new User("Object_"+i,"13592294504");
					System.err.println("add queue info_"+i+"---"+linkQueue.add(u));
				}
				System.err.println("----队列消息总数----"+linkQueue.size());
			}
		});
    	t.start();
    	//测试消息队列
    	Message msg = new Message();
    	msg.setType(MessageType.queue);
    	msg.setTopic("text");
    	msg.setMessage(linkQueue);
    	publishMsg.send(msg);
    }
}
